package io.hxci.modules.tea.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.hxci.common.annotation.SysLog;
import io.hxci.common.utils.PageUtils;
import io.hxci.common.utils.R;
import io.hxci.modules.sys.controller.AbstractController;
import io.hxci.modules.tea.domain.TeaDict;
import io.hxci.modules.tea.domain.TeaInfo;
import io.hxci.modules.tea.service.TeaDictService;
import io.hxci.modules.tea.service.TeaInfoService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("tea/info")
public class TeaInfoController extends AbstractController {
    @Autowired
    private TeaInfoService teaInfoService;
    @Autowired
    private TeaDictService teaDictService;

    @SysLog("查看教职工基本信息")
    @RequestMapping("/query")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = teaInfoService.queryPage(params);
        return R.ok().put("page", page);
    }

    @SysLog("更新教职工基本信息")
    @RequestMapping("saveOrUpdate")
    public R save(@RequestBody TeaInfo teaInfo){
        if(teaInfo.getUserId() == null){
            teaInfo.setUserId(getUserId());
        }
        teaInfoService.saveOrUpdate(teaInfo);
        return R.ok();
    }

    @SysLog("删除教职工基本信息")
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] id){
        teaInfoService.removeByIds(Arrays.asList(id));
        return R.ok();
    }

    @SysLog("编辑教职工基本信息")
    @RequestMapping("/edit/{id}/{type}")
    @ResponseBody
    public R edit(@PathVariable("id") Integer id,@PathVariable("type") String type){
        TeaInfo edit = teaInfoService.getById(id);
        List<TeaDict> list = teaDictService.list(new QueryWrapper<TeaDict>().like(StringUtils.isNotBlank(type),"type", type));

        return R.ok().put("edit", edit).put("kdoptions",list);
    }
 /*   @SysLog("编辑教职工基本信息")
    @RequestMapping("/edit/{id}/{type}")
    @ResponseBody
    public R edit1(@PathVariable("id") Integer id,@PathVariable("type1") String type1){
        TeaInfo edit = teaInfoService.getById(id);
        List<TeaDict> list1 = teaDictService.list(new QueryWrapper<TeaDict>().like(StringUtils.isNotBlank(type1),"type1", type1));
        System.out.println("list:----"+list+"type"+type1);
        list1.forEach(System.out::println);
        return R.ok().put("edit", edit).put("kdoptions",list1);
    }*/
     /*   @SysLog("编辑教职工基本信息")
    @RequestMapping("/edit/{id}/{type}")
    @ResponseBody
    public R edit1(@PathVariable("id") Integer id,@PathVariable("type2") String type2){
        TeaInfo edit = teaInfoService.getById(id);
        List<TeaDict> list2 = teaDictService.list(new QueryWrapper<TeaDict>().like(StringUtils.isNotBlank(type2),"type2", type2));
        System.out.println("list:----"+list+"type"+type2);
        list2.forEach(System.out::println);
        return R.ok().put("edit", edit).put("kdoptions",list2);
    }*/
}
